package com.system.borrow.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.system.borrow.R;
import com.system.borrow.bean.Tag;

import java.util.ArrayList;
import java.util.List;

/**
 * ================================================
 * 作    者：LuCenly(落尘)
 * 版    本：1.0
 * 创建日期：2016/12/1 16:00
 * 描    述：意见标签
 * ================================================
 */
public class TagAdapter extends BaseAdapter{
    List<Tag> list = new ArrayList<>();
    public Context context;
    public LayoutInflater inflater;

    public TagAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public List<Tag> getList() {
        return list;
    }

    public void setList(List<Tag> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view == null){
            view = inflater.inflate(R.layout.item_tag,null);
            viewHolder = new ViewHolder();
            viewHolder.tv_tag = (TextView) view.findViewById(R.id.tv_tag);
            view.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) view.getTag();
        }
        Tag tag = list.get(i);
        viewHolder.tv_tag.setSelected(tag.isSelect());
        viewHolder.tv_tag.setText(tag.getName());
        return view;
    }
    public class ViewHolder{
        TextView tv_tag;
    }
}
